home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / funstrel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1003 b   |  46 lines

  1. /*
  2. \fucref{fun\_str\_el}{void fun\_str\_el ()}
  3.     {}
  4.     {}
  5.     {}
  6.     {}
  7.     {funstrel.c}
  8.     {
  9.  
  10.         This function is called when an {\em op\_str\_el} opcode is enountered.
  11.         The last pushed value is interpreted as a string, the one but last
  12.         pushed value as an index.
  13.  
  14.         The return register {\em reg} is set to an {\em e\_str} variable:
  15.         the character from the string at index {\em index}, terminated by
  16.         $\backslash$0. If index is smaller than 0 or larger than the size of
  17.         the string, {\em reg} holds a null-character.
  18.  
  19.     }
  20. */
  21.  
  22. #include "icm-exec.h"
  23.  
  24. void fun_str_el ()
  25. {
  26.     register int
  27.         index;
  28.     register char
  29.         *str;
  30.     char
  31.         buf [2];
  32.  
  33.     reg = newvar (e_str);
  34.     buf [1] = '\0';
  35.  
  36.     index = (unsigned) stack [sp].vu.intval;
  37.     str   = stack [sp - 1].vu.i->ls.str;
  38.  
  39.     if (index < 0 || index >= (int) strlen (str))
  40.         buf [0] = '\0';
  41.     else
  42.         buf [0] = str [index];
  43.  
  44.     reg.vu.i->ls.str = xstrdup (buf);
  45. }
  46.